#!/bin/bash


dt="`date -d "$d  0 days ago "  "+%Y-%m-%d"`"
base_path=$(dirname $0)
#实时处理 mid_vipEvaluation 表
sh ${base_path}/../sql/select/mid_vipEvaluation_select.sh  |awk -F '\t' -f ${base_path}/../awk/mid_vipEvaluation.awk >${base_path}/../sql/replace/mid_vipEvaluation_replace.sql
sh ${base_path}/../sql/select/mid_vipEvaluation_cd_select.sh  |awk -F '\t' -f ${base_path}/../awk/mid_vipEvaluation.awk >>${base_path}/../sql/replace/mid_vipEvaluation_replace.sql
mysql  -uroot  -proot <${base_path}/../sql/replace/mid_vipEvaluation_replace.sql

mysql -uroot -proot<<EOF
use result;
replace into res_vipEvaluation_all
select a.date,a.stationid,b.sum,a.dealnumber,if(a.star1total is null,0,star1total),if(a.star2total is null,0,star2total),if(a.star3total is null,0,star3total),if(a.star4total is null,0,star4total),if(a.star5total is null,0,star5total)
from mid.mid_vipEvaluation  as a
join
(select substr(minutes,1,10) as days,stationid,sum(oilnumber)as sum from res_oil_vip where substr(minutes,1,10)='${dt}' group by substr(minutes,1,10),stationid) as b
on a.date = b.days and a.stationid = b.stationid
where a.date='${dt}';
EOF

mysql -uroot  -proot -e "replace into result.res_update(res_table) VALUES('res_vipEvaluation_all')"
